<template>
  <div class="sidebar">
    <el-menu
        class="sidebar-el-menu"
        :default-active="onRoutes"
        :collapse="sidebar.collapse"
        background-color="#324157"
        text-color="#bfcbd9"
        active-text-color="#20a0ff"
        unique-opened
        router
    >
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-sub-menu :index="item.index" :key="item.index" v-permiss="item.permiss">
            <template #title>
              <el-icon>
                <component :is="item.icon"></component>
              </el-icon>
              <span>{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-sub-menu
                  v-if="subItem.subs"
                  :index="subItem.index"
                  :key="subItem.index"
                  v-permiss="item.permiss"
              >
                <template #title>{{ subItem.title }}</template>
                <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">
                  {{ threeItem.title }}
                </el-menu-item>
              </el-sub-menu>
              <el-menu-item v-else :index="subItem.index" v-permiss="item.permiss">
                {{ subItem.title }}
              </el-menu-item>
            </template>
          </el-sub-menu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index" v-permiss="item.permiss">
            <el-icon>
              <component :is="item.icon"></component>
            </el-icon>
            <template #title>{{ item.title }}</template>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useSidebarStore } from '../store/sidebar';
import { useRoute } from 'vue-router';

const items = [
  {
    icon: 'Odometer',
    index: '/dashboard',
    title: '系统首页',
    permiss: '1'
  },
  {
    icon: 'Document',
    title: '论文',
    permiss: '15',
    subs: [
      {
        index: '/charts',
        title: '提交论文',
        permiss: '11'
      },
      {
        index: '/permission',
        title: '我的论文',
        permiss: '13'
      },

    ]
  },
  {
    icon: 'Menu',
    title: '项目',
    permiss: '2',
    subs: [
      {
        index: '/tabs',
        title: '提交项目',
        permiss: '3',
      },
      {
        index: '/donate',
        title: '我的项目',
        permiss: '14'
      },
    ]
  },
  {
    icon: 'Document',
    title: '论文&项目',
    permiss: '7',
    subs: [
      {
        index: '/editor',
        title: '已审核论文',
        permiss: '8'
      },
      {
        index: '/form',
        title: '已审核项目',
        permiss: '5'
      },
      // {
      //   index: '/markdown',
      //   title: '未审核论文',
      //   permiss: '9'
      // }
    ]
  },
  {
    icon: 'Menu',
    index: '/upload',
    title: '审核论文&项目',
    permiss: '6'
  },
  // {
  //   icon: 'Menu',
  //   index: '3',
  //   title: '项目-管理员',
  //   permiss: '4',
  //   subs: [
  //     {
  //       index: '/form',
  //       title: '已审核项目',
  //       permiss: '5'
  //     },
  //     {
  //       index: '/upload',
  //       title: '未审核项目',
  //       permiss: '6'
  //     },
  //   ]
  // },
  // {
  //   icon: 'Calendar',
  //   index: '/test',
  //   title: 'test',
  //   permiss: '100',
  // },
  // {
  //   icon: 'Document',
  //   index: '/profile',
  //   title: '个人信息',
  //   permiss: '1',
  // },
  {
    icon: 'Setting',
    index: '/user',
    title: '个人主页',
    permiss: '1',
  }
];

const route = useRoute();
const onRoutes = computed(() => {
  return route.path;
});

const sidebar = useSidebarStore();
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}
</style>